#!/bin/bash

# 测试私有仓库推送功能
# 该脚本用于验证docker_manager.py的私有仓库推送功能

echo "🧪 开始测试私有仓库推送功能..."

# 检查Docker是否运行
if ! docker info > /dev/null 2>&1; then
    echo "❌ Docker未运行，请先启动Docker服务"
    exit 1
fi

# 检查Python脚本是否存在
if [ ! -f "docker_manager.py" ]; then
    echo "❌ docker_manager.py 文件不存在"
    exit 1
fi

echo "📋 测试场景1: 构建并推送镜像到私有仓库"
python docker_manager.py build --registry-tag v1.0.0 --push

if [ $? -eq 0 ]; then
    echo "✅ 场景1测试通过"
else
    echo "❌ 场景1测试失败"
fi

echo ""
echo "📋 测试场景2: 仅构建镜像（不推送）"
python docker_manager.py build --registry-tag v1.0.0-test

if [ $? -eq 0 ]; then
    echo "✅ 场景2测试通过"
else
    echo "❌ 场景2测试失败"
fi

echo ""
echo "📋 测试场景3: 推送已存在的镜像"
python docker_manager.py build --tag latest
python docker_manager.py push v1.0.0

if [ $? -eq 0 ]; then
    echo "✅ 场景3测试通过"
else
    echo "❌ 场景3测试失败"
fi

echo ""
echo "📋 测试场景4: 检查镜像标签"
echo "本地镜像列表："
docker images | grep openssh-synchronization

echo ""
echo "📋 测试场景5: 验证推送结果（需要私有仓库访问权限）"
echo "镜像推送验证："
echo "- 仓库地址: harbor.liumou.site/arm64/openssh-synchronization"
echo "- 标签: v1.0.0"
echo "- 请登录私有仓库查看推送结果"

echo ""
echo "🎉 测试完成！"
echo ""
echo "📖 使用说明："
echo "1. 构建并推送: python docker_manager.py build --registry-tag v1.0.0 --push"
echo "2. 仅构建: python docker_manager.py build --registry-tag v1.0.0"
echo "3. 仅推送: python docker_manager.py push v1.0.0"
echo "4. 查看帮助: python docker_manager.py --help"